#!/usr/bin/env python 
# -*- coding:utf-8 -*-
"""
@Time:2021/12/26 7:01 下午"
@Author:lydia_liu"
@File:base.py
@function: 管理APP相关工作
启动APP，关闭APP，重启APP

作业：
1、加入日志
2、实现数据驱动（姓名，手机号）
3、对应desired_caps数据保存到数据文件中维护起来，读取yaml文件
"""
import logging

import yaml
from appium import webdriver

from po_app_object.app_wechat_page.page.main_page import MainPage


class basepage:
    def start(self):
        #启动APP :用yaml数据保存到文件数据中，读取yaml文件获取
        data = yaml.safe_load(open('../datas/desired_caps.yaml','r'))
        desired_caps = {}
        desired_caps['platformName'] = data['platformName']
        desired_caps['platformVersion'] = data['platformVersion']
        desired_caps['deviceName'] = data['deviceName']
        desired_caps['appPackage'] = data['appPackage']
        # 获取启动页的命令  adb logcat ActivityManager |grep "cmp"
        desired_caps['appActivity'] = data['appActivity']
        # 累计保留上次登录或操作过关闭弹窗等操作，不清空操作数据
        desired_caps['noReset'] = data['noReset']
        desired_caps['skipServerInstallation'] = data['skipServerInstallation']
        self.driver = webdriver.Remote(f"http://{data['ip']}:{data['port']}/wd/hub", desired_caps)
        self.driver.implicitly_wait(15)
        logging.info("logging app start....")

        return self

    def stop(self):
        self.driver.quit()

    def restart(self):
        pass

    def goto_main(self):

        return MainPage(self.driver)


